module map2D {
	export class MapBricker {
		private _sceneLay:GYLite.GYSprite;
		// private _brickArray:any;
		private _matrix:egret.Matrix;
		private _sceneW:number;
		private _sceneH:number;
		public constructor(sceneLayer:GYLite.GYSprite) {
			let s = this;
			s._sceneLay = sceneLayer;
			// s._brickArray = {};
			s._matrix = new egret.Matrix;			
		}
		public setSceneSize(w:number,h:number):void
		{
			let s = this;
			s._sceneW = w;
			s._sceneH = h;
		}
		public clearBricks():void
		{			
			let s = this;			
			// for(var key in s._brickArray)
			// {
			// 	s._brickArray[key].graphics.clear();
			// 	// s._brickArray[key].clearBitmapFill();
			// }
			s._sceneLay.graphics.clear();
		}
		public brickDraw(x:number,y:number,innerCol:number,innerRow:number,aliasTex:egret.Texture,aliasId:string,areaSize:number=512):void
		{
			let s = this;
			// let brick:Brick;
			if(aliasTex == null)return;
			// if(s._brickArray[aliasId] == null)
			// {
			// 	brick = s._brickArray[aliasId] = new Brick();						
			// 	s._sceneLay.addChild(brick);
			// }
			// else
			// 	brick = s._brickArray[aliasId];			
			let tx:number,ty:number,drawX:number,drawY:number,drawW:number,drawH:number;
			tx = x;
			ty = y;
			s._matrix.tx = (-innerCol * areaSize | 0) + tx;
			s._matrix.ty = (-innerRow * areaSize | 0) + ty;			
			let g:GYLite.GYGraphics;
			// g = <GYLite.GYGraphics>brick.graphics;			
			g = <GYLite.GYGraphics>s._sceneLay.graphics;
			drawX = tx < 0?0:tx;
			drawY = ty < 0?0:ty;
			drawW = tx < 0?areaSize+tx:(tx + areaSize>s._sceneW?s._sceneW - tx:areaSize);
			drawH = ty < 0?areaSize+ty:(ty + areaSize>s._sceneH?s._sceneH - ty:areaSize);
			if(drawW == 0 || drawH == 0)
				return;
			g.beginBitmapFill(aliasTex, s._matrix, false);			
			if(drawX + drawW - s._matrix.tx > aliasTex.$bitmapWidth)
				drawW = aliasTex.$bitmapWidth - drawX;
			if(drawY + drawH - s._matrix.ty > aliasTex.$bitmapHeight)
				drawH = aliasTex.$bitmapHeight - drawY;			
			g.drawRect(drawX,drawY,drawW,drawH);
			g.endFill();
		}		
	}	
	// export class Brick extends GYLite.GYSprite
	// {

	// }
	// export class Brick extends egret.Bitmap{
	// 	private _renderMatrix:egret.Matrix;
	// 	public constructor(value:egret.Texture = null,rect:GYLite.Scale9GridRect=null)
	// 	{
	// 		super(value);
	// 		let s = this;
	// 		s.$renderNode = new egret.sys.BitmapNode;						
	// 	}
	// 	public beginBitmapFill(m:egret.Matrix, r:boolean):void
	// 	{
	// 		var s = this;
	// 		var node:any;			
	// 		node = s.$renderNode;
	// 		node.GYFill = 1;//位图填充标志
	// 		node.image = s.texture;
	// 		node.imageHeight = s.texture.$sourceWidth;
	// 		node.imageWidth = s.texture.$sourceHeight;
	// 		node.smoothing = s.smoothing;
	// 		s._renderMatrix = m;			
	// 	}
	// 	public drawRect(tX:number, tY:number, w:number, h:number):void
	// 	{
	// 		var s = this;
	// 		var node:any = s.$renderNode;
	// 		var sclX:number,sclY:number;					
			
	// 		sclX = s._renderMatrix.a;
	// 		sclY = s._renderMatrix.d;
	// 		node.drawData.push(s.texture.$bitmapX - s._renderMatrix.tx + tX, s.texture.$bitmapY - s._renderMatrix.ty + tY, w/sclX, h/sclY, s.texture.$offsetX + tX, s.texture.$offsetY + tY, w, h);
	// 		++node.renderCount;						
	// 		s.$renderDirty = true;
	// 	}
	// 	public clearBitmapFill():void
	// 	{
	// 		var s = this;
	// 		s.$renderNode.cleanBeforeRender();
	// 	}
	// }
}